package org.lanqiao.tjut.control;

import javax.annotation.Resource;

import org.lanqiao.tjut.bean.UsersEntity;
import org.lanqiao.tjut.service.IUserInfoService;
import org.lanqiao.tjut.service.impl.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

//不能加括号
@Controller
//@RequestMapping("/user")
public class UserLoginControl {
	@Resource
	private IUserInfoService userService;

	@RequestMapping(value = "/login", method = RequestMethod.POST)
	//传值   数据库验证
	public String doLogin(String userName, Model model) {
		System.out.println(userName + "正在进行登录处理。。。");
		UsersEntity userE = userService.selectUsersInfo(2);
		String strName = (userE == null ? "" : userE.getUsername());
		System.out.println("数据库查询的用户信息为：" + strName);
		//视图对象
		model.addAttribute("loggerName", strName);
		return "logined";
	}
	
	/**
	 * 两种方法  
	 * ModelAndView方法  提取表单数据
	 * @param userE
	 * @return
	 */
	@RequestMapping("/login2")
	public ModelAndView doLogin2(UsersEntity userE) {
		ModelAndView model = new ModelAndView();
		model.setViewName("logined");
		UsersEntity userE0 = userService.selectUsersInfo(2);
		String strName = (userE0 == null ? "" : userE0.getUsername());
		System.out.println("数据库查询的用户信息为：" + strName);
		model.addObject("loggerName", strName);
		return model;
	}
	
}
